package day08;

import java.util.Arrays;
import java.util.Date;

public class StringMethodDemo {
    public static void main(String[] args) {
        String str = "abc";

        char c = str.charAt(1);
        System.out.println(c);

        System.out.println(str.length());

        for(int i = 0;i<str.length();i++){
            System.out.println(str.charAt(i)+"\t");
        }
        System.out.println();

        String s1 = "ab";

        String s2 = s1.concat("c");
        System.out.println(s2);

        System.out.println("abc" == s2);
        System.out.println(s2.contains("ab"));

        System.out.println("xxx.java".endsWith("java"));
        System.out.println("Javascript".startsWith("Java"));

        System.out.println("abc".equalsIgnoreCase("ABC"));
        String strDate = String.format("%tF",new Date());
        System.out.println(strDate);

        System.out.println("abcbc".indexOf("bc"));
        String x1 = "";
        System.out.println(x1.isEmpty());

        String x2 = "I Love you";
        String x3 = x2.replace("you","java");
        System.out.println(x3);

        String arr = "192:168:0:31";
        String[] ips = arr.split("\\:");
        System.out.println(Arrays.toString(ips));

        String letter = "I 12Lo3232v232e 232y232o232u";
        //将里面的所有的字母找出来.
        String[] words = letter.split("[0-9]+");
        System.out.println(Arrays.toString(words));

        //字符串的截取
        String x4 = "java";
        // String x5 = x4.substring(1);
        //[start,end)
        String x5 = x4.substring(1,3);//av
        System.out.println(x5);

        System.out.println("av" == x5);//false

        //注意点
        String x6 = "abc";
        String x7 = x6.substring(0);//"abc"
        System.out.println(x7 == "abc");//true - 如果下标第一个是0,底层是直接返回this

        //将字符串转换成char数组
        char[] arr2 = x6.toCharArray();
        System.out.println(arr2);//abc
        //特殊的一点

        //大小写的转换
        System.out.println("abc".toUpperCase());
        System.out.println("ABC".toLowerCase());

        //去除字符串左右两边的空格
        System.out.println("   空   格   ".trim());

        System.out.println("      ".trim().length());//0

        //将其他类型转换成字符串类型
        //int->String
        String result = String.valueOf(10);
        System.out.println(result);
    }
}
